package com.lyf.language.practice.practice_6_21.lang;

/**
 * 执行顺序：
 * 静态（按照顺序进行加载属性OR代码块，方法需要调用才响应） → 非静态 （构造函数→方法调用）
 *
 * @author LYF
 * @date 2022/6/21
 */
class OutClass{

}

public class ClassKind {
    // 成员变量--属性
    private String privateAtr = "hello,private";
    String defaultAtr = "hello,default";
    protected String protectedAtr = "hello,protected";
    public String publicAtr = "hello,public";

    private static String staticStr = "hello,static";
    private static String staticStr2 = null;

    // 静态代码块
    static {
        System.out.println("load static block...");
        staticStr2 = "hello,static2";
    }
    private ClassKind(){
        System.out.println("load ClassKind Constructor...");
    }
    // 静态内部类
    static private class InnerClass1{
        private InnerClass1(){
            System.out.println("load InnerClass1 Constructor...");
        }
        static final ClassKind INSTANCE=new ClassKind();
    }
    private class InnerClass2{
        private InnerClass2(){
            System.out.println("load InnerClass2 Constructor...");
        }
        //Inner classes cannot have static declarations
        //static final ClassKind INSTANCE=new ClassKind();
        final ClassKind INSTANCE=new ClassKind();
    }

    static void staticOperation(){
        System.out.println("classKind static opt");
    }
    void nonStaticOperation(){
        System.out.println("classKind nonstatic opt");
    }

    @Override
    protected void finalize() throws Throwable {
        System.out.println("destroy");
        super.finalize();
    }

    public static void main(String[] args) {
           System.out.println(InnerClass1.INSTANCE);
           ClassKind classKind = new ClassKind();
           classKind.nonStaticOperation();
           classKind.staticOperation();

        try {
            classKind.finalize();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }

}
